package com.comac.tasks.manager.app.common.enums;

import lombok.Getter;

import java.util.Arrays;

/**
 * @author: wfb
 * @Date: 2021年12月22日17:33:32
 * @Description: 办理类型
 */
public enum DealTypeEnum {
    /**
     * 待办状态枚举
     */
    DONE("DONE", "已办"),
    TODO("TODO", "待办"),
    PAUSE("PAUSE", "已暂停"),
    RECALL("RECALL", "已撤回"),
    CANCEL("CANCEL", "已撤销"),
    ROLLBACK("ROLLBACK", "已退回"),
    REJECT("REJECT", "不同意"),
    END("END", "已终止");

    /**
     * 代码
     */
    @Getter
    private String code;

    /**
     * 类型
     */
    @Getter
    private String type;
    public static String getType(String code) {
        for (DealTypeEnum c : DealTypeEnum.values()) {
            if (code.equals(c.getCode())) {
                return c.getType();
            }
        }
        return null;
    }

    public static String getCode(String type) {
        for (DealTypeEnum c : DealTypeEnum.values()) {
            if (type.equals(c.getType())) {
                return c.getCode();
            }
        }
        return null;
    }
    DealTypeEnum(String code, String type) {
        this.code = code;
        this.type = type;
    }

    public static DealTypeEnum match(String no) {
        if (no == null) {
            return null;
        }
        DealTypeEnum[] enums = DealTypeEnum.values();
        return Arrays.stream(enums).filter(item -> item.code.equals(no)).findAny().orElse(null);
    }
}
